<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>

</html>
<script>
    function sss(obj){
        var str=''
        for(var key in obj){
            str+=`${key}=${obj[key]}&`
        }
        return str.slice(0,str.length-1)
    }
    function ajax(fangshi,url,canshu,hd) {
        //1.先创建请求对象
        var xhr = new XMLHttpRequest()
        //2.配置请求对象参数
        xhr.open(fangshi,fangshi=='get'?url+'?'+sss(canshu):url)
        //3.配置回调函数
        xhr.onreadystatechange=function(){
            if(xhr.readyState==4){
                hd(JSON.parse(xhr.responseText))
            }
        }
        //4.最后发送
        xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
        xhr.send(fangshi=='get'?null:sss(canshu,))
    }
</script>